import 'package:flutter/material.dart';

class WillPopScopeExample extends StatefulWidget {
  @override
  _WillPopScopeExampleState createState() => _WillPopScopeExampleState();
}

class _WillPopScopeExampleState extends State<WillPopScopeExample> {
  DateTime _dateTime;
  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () async {
        if (_dateTime == null ||
            DateTime.now().difference(_dateTime) > Duration(seconds: 1)) {
          _dateTime = DateTime.now();
          return false;
        }
        return true;
      },
      child: Container(
        child: Text('1秒内连续点击两次返回键则退出APP'),
        alignment: Alignment.center,
      ),
    );
  }
}
